# coding=utf-8

from django.db import models
from django.conf import settings
from apps.account.models import User

class Employee(models.Model):
    name = models.CharField(max_length=100, verbose_name=u"姓名")
    tel = models.CharField(max_length=50, verbose_name=u'电话')
    gender = models.PositiveSmallIntegerField(choices=settings.GENDER_CHOICES, verbose_name=u'性别')
    user = models.OneToOneField(settings.AUTH_USER_MODEL, editable=False, related_name='employee', on_delete=models.PROTECT, verbose_name=u'职工')

    class Meta:
        db_table = "employee"
        verbose_name = u"员工管理"
        ordering = ['-id']
        index_together = (
            'name',
            'tel',
            'gender',
        )
        default_permissions = ()
        permissions = [
            ('browse_employee', u'查看'),
            ('add_employee', u'添加'),
            ('edit_employee', u'修改'),
        ]

    @staticmethod
    def create_admin(username, password):
        user = User.objects.create_superuser_tenant(username, password)
        instance = Employee.objects.create(
            name=username,
            tel='',
            gender=settings.MALE,
            user=user
        )
        return instance

